﻿@{
    ViewBag.Title = "AccountResert";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@{
    var action = ViewData["action"].ToString();
    string Id = ViewData["Id"].ToString();

    string width = ViewData["width"].ToString();
    if (action == "edit")
    {
        Id = ViewData["Id"].ToString();
    }

} 

<div class="mod_dialog" style="display:block;margin-top:@width;left:0px">
    <form id="frmAccount" class="layui-form" lay-filter="frmAccount">
        <div class="hd">
            <h3>重置密码</h3>
        </div>
        <div class="bd">
            <div class="form clearfix nouse" data-col="0">

                <ul class="clearfix">
                    <li>
                        <label class="label">账号：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" class="disabled" name="USERNAME" lay-filter="USERNAME" required lay-verify="required" autocomplete="off" class="layui-input" disabled="disabled">
                        </div>

                    </li>
                    <li>
                        <label class="label">类型：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" class="disabled" name="ROLE" lay-filter="ROLE" required lay-verify="required" autocomplete="off" class="layui-input" disabled="disabled">
                        </div>
                    </li>
                    <li>
                        <label class="label">姓名：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" class="disabled" name="NAME" lay-filter="NAME" required lay-verify="required" autocomplete="off" class="layui-input" disabled="disabled">
                        </div>

                    </li>
                    <li>
                        <label class="label">新密码：</label>
                        <div class="inptxt">
                            <p></p>
                            <input type="text" name="PASSWORD" lay-filter="PASSWORD" required lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </li>
                </ul>
            </div>
            </div>
                <div class="fd">
                    <div class="load_btn">
                        @{if (action == "add")
                        {
                            <button class="btn_green_m" id="btnAdd" lay-submit lay-filter="btnAdd">保存</button>
                            <button class="btn_gray_m" id="btnCancel">取消</button>
                        }
                          else
                          {
                            <button class="btn_green_m" id="btnEdit" lay-submit lay-filter="btnEdit">保存</button>
                            <button class="btn_gray_m" id="btnCancel">取消</button>
                        }}

                    </div>
                </div>
    </form>
</div>
<script type="text/javascript">

    $(function () {
        if ("@action" == "edit") {
            $.ajax({
                url: "/Setting/GetAccountByUserId/@Id",
                type: "get",
                dataType: "json",
                success: function (data) {
                    var form = layui.form;
                    form.val("frmAccount", data);
                    form.render(); //刷新select选择框渲染
                }
            });
        }
        var form = layui.form;
        form.render(); //刷新select选择框渲染

        form.on('submit(btnEdit)', function (data) {
           var account = $.extend(data.field, { USER_ID: "@Id" });
            com.ajax({
                url: "/Setting/EditPassword", type: "post", dataType: "json", data: account, success: function (data) {
                    parent.$("#infoList").datagrid("load");
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                }
            });
            return false;
        });
    })


    $("#btnCancel").click(function () {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index); //再执行关闭
        return false;
    });


    @*$("#btnEdit").click(function () {
        var account = com.serializeObj("frmAccount");
        account.USER_ID = "@Id";
        com.ajax({
            url: "/Setting/EditPassword", data: account, type: "post", dataType: "json", success: function (data) {
                parent.$("#infoList").datagrid("load");
                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                parent.layer.close(index); //再执行关闭
            }
        });
        return false;
    });*@

</script>